<?php
	
	// Load basic classes
	
	require_once $dir_src. $DS . 'PModel.php';
	require_once $dir_src. $DS . 'PView.php';
	require_once $dir_src. $DS . 'PController.php';
	
	require_once $dir_src. $DS . 'PDataContainer.php';
	require_once $dir_src. $DS . 'PDatabaseConnection.php';
	require_once $dir_src. $DS . 'PDatabase.php';
	require_once $dir_src. $DS . 'PDataset.php';
	
	//require_once $dir_src. $DS . 'PDebugger.php';
	
	require_once $dir_src. $DS . 'PExtensionManager.php';
	require_once $dir_src. $DS . 'PDataManager.php';
	require_once $dir_src. $DS . 'PFlowManager.php';
	require_once $dir_src. $DS . 'PViewManager.php';
	
	
	class Puzzle
	{
		var $PEM;
		
		var $PVM;
		var $PDM;
		var $PFM;
		
		var $config;
		
		
		function Puzzle($config)
		{
			$PEM = new PExtensionManager($this);
			$PVM = new PViewManager($this);
			$PDM = new PDataManager($this);
			$PFM = new PFlowManager($this);
			
			$this->PEM = $PEM;
			$this->PVM = $PVM;
			$this->PDM = $PDM;
			$this->PFM = $PFM;
			
			$this->config = $config;
			
			$this->config['version'] = "2.0";
			$this->config['release_date'] = "2011-02-14";
	
			$this->initDatabase();
		}
		
		function initDatabase()
		{
			$host = $this->config['db_host'];
			$port = $this->config['db_port'];
			$name = $this->config['db_name'];
			$user = $this->config['db_user'];
			$pass = $this->config['db_pass'];
			$prefix = $this->config['db_prefix'];
			
			if ($host != "" && $name != "" && $user != "" && $pass != "")
			{
				$db = new PDatabase($this);
				$db->connect("default", $host, $name, $user, $pass);
				$this->PDM->addContainer($db);
			}
		}
		
		function bang()
		{
			$this->PFM->executeController("bang", "php-puzzle-bigbang");
		}
	}

?>
